<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="16">
        <el-button @click="resetNameFilter">清除客户名称过滤器</el-button>
        <el-button @click="clearFilter">清除所有过滤器</el-button>
        <!-- <div style="display:inline">
          <el-input
            placeholder="请输入内容"
            prefix-icon="el-icon-search"
            v-model="svalue"
            size="medium"
            
          >
          </el-input>
        </div> -->
      </el-col>
      <el-col :span="8">
        <el-button type="primary" @click="dialogFormVisible = true"
          >关注客户</el-button
        >

        <el-dialog title="关注客户" :visible.sync="dialogFormVisible">
          <el-form :model="form">
            <el-form-item label="客户编号" label-width="120px">
              <el-input v-model="form.code" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="授权码" label-width="120px">
              <el-input v-model="form.key" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogFormVisible = false"
              >确 定</el-button
            >
          </div>
        </el-dialog>

        <el-button @click="deleteRows">批量取消关注</el-button>
      </el-col>
    </el-row>
    <el-table
      ref="filterTable"
      :data="tableData"
      style="width: 100%"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
      >>
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="code" label="客户编号" sortable> </el-table-column>
      <el-table-column
        prop="name"
        label="客户名称"
        sortable
        column-key="name"
        :filters="getFilters('name')"
        :filter-method="filterHandler"
      >
      </el-table-column>
      <el-table-column prop="address" label="地址"> </el-table-column>
      <el-table-column prop="phone" label="电话"> </el-table-column>
      <el-table-column prop="contact" label="联系人"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.$index, tableData)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// import table from "../../components/clients/table";
export default {
  components: {
    // table,
  },
  data() {
    return {
      svalue: "",
      form: {
        code: "",
        key: "",
      },
      dialogFormVisible: false,
      tableData: [
        {
          code: 1068,
          name: "广州气站",
          address: "上海市普陀区金沙江路 1518 弄",
          phone: "",
          contact: "",
        },
        {
          code: 1063,
          name: "深圳智物联",
          address: "上海市普陀区金沙江路 1517 弄",
          phone: "",
          contact: "",
        },
        {
          code: 1035,
          name: "深圳一号气站",
          address: "上海市普陀区金沙江路 1519 弄",
          phone: "",
          contact: "",
        },
        {
          code: 1036,
          name: "深圳二号气站",
          address: "上海市普陀区金沙江路 1516 弄",
          phone: "",
          contact: "",
        },
        {
          code: 1040,
          name: "深圳七号气站",
          address: "上海市普陀区金沙江路 1516 弄",
          phone: "",
          contact: "",
        },
        {
          code: 1045,
          name: "广州一号气站",
          address: "上海市普陀区金沙江路 1516 弄",
          phone: "",
          contact: "",
        },
        {
          code: 1046,
          name: "东莞二号气站",
          address: "上海市普陀区金沙江路 1516 弄",
          phone: "",
          contact: "",
        },
        {
          code: 1047,
          name: "惠州一号号气站",
          address: "上海市普陀区金沙江路 1516 弄",
          phone: "",
          contact: "",
        },
      ],
      multipleSelection: [],
    };
  },
  methods: {
    resetNameFilter() {
      this.$refs.filterTable.clearFilter("name");
    },
    clearFilter() {
      this.$refs.filterTable.clearFilter();
    },
    formatter(row, column) {
      return row.address;
    },
    filterTag(value, row) {
      return row.tag === value;
    },
    filterHandler(value, row, column) {
      const property = column["property"];
      return row[property] === value;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
      this.tableData.splice(index, 1);
    },
    deleteRows() {
      for (let i of this.multipleSelection) {
        for (let j in this.tableData) {
          if (i.code == this.tableData[j].code) {
            this.tableData.splice(j, 1);
          }
        }
      }
    },
    getFilters(key) {
      let arr = [];
      for (let i of this.tableData) {
        arr.push({
          text: i[key],
          value: i[key],
        });
      }
      return arr;
    },
    handleRowClick(row, column, event) {
      // console.log(row,column)
      this.$router.push({
        path: "/clients/details",
        // name: 'mallList',
        query: {
          code: row.code
        },
      });
    },
  },
};
</script>

<style>
</style>